From e50ccf7384ea78bec4f23459c34ecf3b380aa7f6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 Oct 2015 15:50:58 -0700 Subject: [PATCH] Always use the root package's set of profiles When testing or building multiple packages via the `-p` argument the root package's profiles should always be used instead of the sub-package's set of profiles. --- src/cargo/ops/cargo_compile.rs | 18 ++++++++++------- tests/test_cargo_test.rs | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index e9263a69d..d4c4fef47 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -29,7 +29,7 @@ use std::sync::Arc; use core::registry::PackageRegistry; use core::{Source, SourceId, PackageSet, Package, Target}; -use core::{Profile, TargetKind}; +use core::{Profile, TargetKind, Profiles}; use core::resolver::Method; use ops::{self, BuildOutput, ExecEngine}; use util::config::{ConfigValue, Config}; @@ -145,10 +145,11 @@ pub fn compile_pkg<'a>(root_package: &Package, }; let resolved_with_overrides = - try!(ops::resolve_with_previous(&mut registry, root_package, method, - Some(&resolve), None)); + try!(ops::resolve_with_previous(&mut registry, root_package, + method, Some(&resolve), None)); - let packages = try!(ops::get_resolved_packages(&resolved_with_overrides, &mut registry)); + let packages = try!(ops::get_resolved_packages(&resolved_with_overrides, + &mut registry)); (packages, resolved_with_overrides, registry.move_sources()) }; @@ -176,10 +177,12 @@ pub fn compile_pkg<'a>(root_package: &Package, let mut general_targets = Vec::new(); let mut package_targets = Vec::new(); + let profiles = root_package.manifest().profiles(); match *target_rustc_args { Some(args) => { if to_builds.len() == 1 { - let targets = try!(generate_targets(to_builds[0], mode, filter, release)); + let targets = try!(generate_targets(to_builds[0], profiles, + mode, filter, release)); if targets.len() == 1 { let (target, profile) = targets[0]; let mut profile = profile.clone(); @@ -199,7 +202,8 @@ pub fn compile_pkg<'a>(root_package: &Package, } None => { for &to_build in to_builds.iter() { - let targets = try!(generate_targets(to_build, mode, filter, release)); + let targets = try!(generate_targets(to_build, profiles, mode, + filter, release)); package_targets.push((to_build, targets)); } } @@ -273,11 +277,11 @@ impl<'a> CompileFilter<'a> { /// Given the configuration for a build, this function will generate all /// target/profile combinations needed to be built. fn generate_targets<'a>(pkg: &'a Package, + profiles: &'a Profiles, mode: CompileMode, filter: &CompileFilter, release: bool) -> CargoResult> { - let profiles = pkg.manifest().profiles(); let build = if release {&profiles.release} else {&profiles.dev}; let test = if release {&profiles.bench} else {&profiles.test}; let profile = match mode { diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 7a269f26a..f5ebe9dcc 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -2021,3 +2021,39 @@ test!(bin_does_not_rebuild_tests { {running} `rustc src[..]main.rs [..]` ", compiling = COMPILING, running = RUNNING))); }); + +test!(selective_test_wonky_profile { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [profile.release] + opt-level = 2 + + [dependencies] + a = { path = "a" } + "#) + .file("src/lib.rs", "") + .file("a/Cargo.toml", r#" + [package] + name = "a" + version = "0.0.1" + authors = [] + "#) + .file("a/src/lib.rs", ""); + p.build(); + + assert_that(p.cargo("test").arg("-v").arg("--no-run").arg("--release") + .arg("-p").arg("foo").arg("-p").arg("a"), + execs().with_status(0).with_stdout(&format!("\ +{compiling} a v0.0.1 ([..]) +{running} `rustc a[..]src[..]lib.rs [..]` +{running} `rustc a[..]src[..]lib.rs [..]` +{compiling} foo v0.0.1 ([..]) +{running} `rustc src[..]lib.rs [..]` +{running} `rustc src[..]lib.rs [..]` +", compiling = COMPILING, running = RUNNING))); +}); -- 2.30.2